home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / castools.zip / LOOKUPSE.C < prev    next >
Text File  |  1989-12-20  |  3KB  |  87 lines

  1.  
  2.  
  3. /*
  4.    LOOKUP.C  Function PbLookUpSendInfo:  Fetches the phone number, comm
  5.       hardware type, and possible the name of a phone book entry.
  6.  
  7.    INPUT:  Phonebook structure and either the name or the record ID of an
  8.       entry to look up.
  9.  
  10.    OUTPUT: If successful, the phone number, hw type, and name of entry.
  11. */
  12.  
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <phonebk.h>
  17.  
  18. int pascal PbLookUpSendInfo(PB *pb,
  19.                             char *name,
  20.                             int *recordID,
  21.                             char *PhoneNumber,
  22.                             BYTE *CommHardware)
  23. {
  24.   PBEFIXED fixed_part, *retval;
  25.   int rid;
  26.  
  27.   Pberrno = 0;            /* Initially, always reset */
  28.  
  29.   /* First, check params */
  30.   if ((pb == NULL) ||
  31.       (name == NULL) ||
  32.       (recordID == NULL) ||
  33.       (PhoneNumber == NULL) ||
  34.       (CommHardware == NULL)) {
  35.     Pberrno = INVALIDPARAMETER;
  36.     return(FAIL);
  37.   }
  38.   if ((*recordID < -1) ||
  39.       (*recordID > 999)) {
  40.     Pberrno = INVALIDPARAMETER;
  41.     return(FAIL);
  42.   }
  43.  
  44.   /* If the record id is given, find the record at offset at that record id */
  45.   if (*recordID != -1) {
  46.     retval = GetFixedPart(pb, &fixed_part, *recordID);
  47.     if (!retval) {
  48.       if (!Pberrno) {
  49.         Pberrno = NOENTRYPRESENT;          /* No offset at that record id */
  50.       }
  51.       return(FAIL);
  52.     }
  53.     strncpy(name, fixed_part.name, NAMELENGTH);
  54.     strncpy(PhoneNumber, fixed_part.PhoneNumber, PHONENUMLENGTH);
  55.     *CommHardware = fixed_part.HardwareType;
  56.     *recordID = fixed_part.id;
  57.     return(SUCCESS);
  58.   }
  59.  
  60.   /* Otherwise, use the string as a search key through all rid's, until found */
  61.   else {
  62.     for (rid=0; rid<1000; rid++) {
  63.       retval = GetFixedPart(pb, &fixed_part, rid);
  64.       if (!retval) {
  65.         if (Pberrno) { /* Not just that no entry there, but an error occurred */
  66.           return(FAIL);
  67.         }
  68.       }
  69.       else {               /* an entry was fetched; check its name */
  70.         if (!(strnicmp(name,
  71.                        fixed_part.name,
  72.                        NAMELENGTH))) {         /* if a case-insensitive match */
  73.  
  74.           strncpy(name, fixed_part.name, NAMELENGTH);   /* just in cAsE (sic) */
  75.           strncpy(PhoneNumber, fixed_part.PhoneNumber, PHONENUMLENGTH);
  76.           *CommHardware = fixed_part.HardwareType;
  77.           *recordID = fixed_part.id;
  78.           return(SUCCESS);
  79.         }
  80.       }
  81.     }
  82.     /* If we've gotten here, no matching entries were found */
  83.     Pberrno = NOENTRYFOUND;
  84.     return(FAIL);
  85.   }
  86. }
  87.